import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
import { getAccessToken } from '@/utils/auth'
const { wsCache } = useCache()

;(() => {
  const url = window.location.href
  // 使用URL对象解析URL
  const parsedUrl = new URL(url)
  const queryParams = parsedUrl.searchParams

  // 转换所有查询参数键为小写
  const lowerCaseParams = new URLSearchParams()
  queryParams.forEach((value, key) => {
    if (value) {
      lowerCaseParams.set(key.toLowerCase(), value)
    }
  })
  // 使用转换后的查询参数获取tenantId，忽略大小写
  const tenantId = lowerCaseParams.get('tenantid')

  console.log('tenantId:', tenantId)
  if (tenantId && !getAccessToken()) {
    wsCache.set(CACHE_KEY.TenantId, tenantId)
  }
})()
